package com.neusoft.neuiotms.notice;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.bizcore.auth.common.service.AuthUserDetailsService;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.neuiotms.micro.auth.AuthMicroService;

@Configuration
public class NoticeConfiguration {
    @Bean
    @ConditionalOnMissingBean(AuthUserDetailsService.class)
    public AuthUserDetailsService authUserDetailsService(final AuthMicroService authMicroService) {
        return username -> {
            final ResultDTO<UserBean> result = authMicroService.loadUserByUsername(username);
            return result.getData();
        };
    }

    @Component
    class ContainerFactoryConfigurer {
        ContainerFactoryConfigurer(final ConcurrentKafkaListenerContainerFactory<?, ?> factory) {
            factory.getContainerProperties().setMissingTopicsFatal(false);
        }
    }

}
